﻿Imports DAO
Imports DTO

Public Class PhieuThuBUS

    Public Sub ThemPhieuThu(ByVal phieu As PhieuThuDTO)

        Dim kh As New KhachHangDAO
        Dim dt As New DataTable

        dt = kh.LayTienNo(phieu)
        Dim tienno As Integer = Integer.Parse(dt(0)("TongTienNo"))
        If tienno = 0 Then
            Throw New Exception("Khách hàng  không có nợ tiền")
        End If
        If tienno < phieu.LayTienThu Then
            Throw New Exception("Số tiền thu lớn hơn số tiền khách hàng đang nợ")
        End If
        Dim p As New PhieuThuDAO
        p.ThemPhieuThu(phieu)
    End Sub

    Public Function LayPhieuThu(ByVal pt As PhieuThuDTO)
        Dim dt As New DataTable
        Dim phieu As New PhieuThuDAO
        dt = phieu.LayPhieuThu(pt)
        Return dt
    End Function

    Public Sub XoaPhieuThu(ByVal pt As PhieuThuDTO)
        Dim phieu As New PhieuThuDAO
        phieu.XoaPhieuThu(pt)
    End Sub

    Public Function RefreshPhieuThu(ByVal pt As PhieuThuDTO) As DataTable
        Dim dt As New DataTable
        Dim phieu As New PhieuThuDAO
        dt = phieu.RefreshPhieuThu(pt)
        Return dt
    End Function

End Class
